﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Logic.Personal;
using Job.Logic.Common;

namespace Job.Web.userControls.Personal
{
    public partial class AddItems : BaseCtrl
    {
        int personalid = myR["resumeid"].IntValue;
        PersonalLogic pl = new PersonalLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            string rightParams = string.Format("AddToRight(\"{0}\",\"{1}\",\"{2}\",\"{3}\");",
                this.selectedhopeaddressid.ClientID,this.ddlparent.ClientID,
                this.ddlSub.ClientID,this.lbItems.ClientID);
            string leftParams = string.Format("AddToLeft(\"{0}\",\"{1}\");", this.lbItems.ClientID,
                this.selectedhopeaddressid.ClientID);

            this.btntoright.Attributes.Add("onclick", rightParams);
            this.btnToLeft.Attributes.Add("onclick", leftParams);

            if (!Page.IsPostBack)
            {
                LoadData();
            }
        }

        private Constants.DictionaryType _type = Constants.DictionaryType.INDUSTRY_CLASS;

        public Constants.DictionaryType DictType
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }

        private void LoadData()
        {
            WebCommon.LoadLevelDropDownList(ddlparent, ddlSub, ddlRlist, "", "", DictType);
            if (HopeValue != "")
            {
                this.selectedhopeaddressid.Value = "," + HopeValue;
            }
            string[] ids = HopeValue.Split(",".ToCharArray());
            
            foreach (string id in ids)
            {
                //GetFullAddrName
                string listText = "";
                if (DictType == Constants.DictionaryType.POSITION_CLASS)
                {
                    listText = MemoryDictionary.GetFullPositionClassName(id);
                }
                else if (DictType == Constants.DictionaryType.INDUSTRY_CLASS)
                {
                    listText = MemoryDictionary.GetFullIndustryName(id);
                }
                else if (DictType == Constants.DictionaryType.ADDR_CITY)
                {
                    listText = MemoryDictionary.GetFullAddrName(id);
                }
                if (listText != "")
                {
                    ListItem item = new ListItem(listText, id);
                    lbItems.Items.Add(item);
                }
            }

        }


        public string HopeValue
        {
            get;
            set;
        }

        public string HopeString
        {
            get
            {
                string value = selectedhopeaddressid.Value.Trim();
                if (value != "")
                {
                    if (value.StartsWith(","))
                    {
                        value = value.Substring(1,value.Length-1);
                    }
                    else if (value.EndsWith(","))
                    {
                        value = value.Substring(0, value.Length - 1);
                    }
                    return value;
                }
                else
                {
                    return string.Empty;
                }
            }
        }
    }
}